<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>KW音乐查询</title>
    <script src="sweetalert.min.js"></script>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f4f4f9;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .container {
            background-color: #ffffff;
            padding: 25px;
            border-radius: 20px;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
            max-width: 450px;
            width: 100%;
            text-align: center;
        }

        h1 {
            font-size: 24px;
            color: #333;
            margin-bottom: 20px;
            letter-spacing: 1px;
        }

        .input-container {
            display: flex;
            justify-content: space-between;
            margin-bottom: 15px;
        }

        input[type="text"] {
            flex-grow: 1;
            padding: 12px;
            border: 2px solid #ff9900;
            border-radius: 10px;
            margin-right: 10px;
            font-size: 16px;
            outline: none;
        }

        button {
            padding: 12px;
            background-color: #ff9900;
            border: none;
            color: white;
            border-radius: 10px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        button:hover {
            background-color: #e68a00;
        }

        .music-container {
            display: none;
            margin-top: 20px;
        }

        .music-info {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 20px;
        }

        .music-info img {
            width: 50%;
            border-radius: 15px;
            margin-right: 15px;
        }

        .music-details {
            text-align: left;
            flex-grow: 1;
        }
        
        .music-details a{
            color: #ff9900;
            text-decoration: none;
        }

        .music-details a:hover{
            color: #e68a00;
            text-decoration: none;
        }

        .music-info p {
            font-size: 16px;
            margin: 8px 0;
            color: #444;
        }

        .player {
            display: flex;
            align-items: center;
            margin-top: 10px;
        }

        .player .play-btn {
            background-color: #ff9900;
            border: none;
            border-radius: 50%;
            width: 35px;
            height: 35px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
        }

        .player .play-btn img {
            width: 17px;
        }

        .progress-container {
            display: flex;
            align-items: center;
            justify-content: space-between;
            flex-grow: 1;
        }

        .progress-container span {
            font-size: 14px;
            color: #555;
        }

        .progress-bar-container {
            width: 100%;
            height: 10px;
            background-color: #ccc;
            border-radius: 5px;
            overflow: hidden;
            position: relative;
            margin: 0 10px;
            cursor: pointer;
        }

        .progress-bar {
            background-color: #ff9900;
            width: 0;
            height: 100%;
            position: absolute;
        }

        .footer-content {
            background-color: #f4f4f9;
            padding: 20px 0;
            text-align: center;
            font-size: 14px;
            color: #777;
            position: fixed;
            bottom: 0;
            left: 0;
            width: 100%;
        }

        .footer-content a {
            font-size: 16px;
            color: #ff9900;
            border: 2px solid #ff9900cc;
            text-decoration: none;
            transition: all 0.5s ease;
        }

        .footer-content a:hover {
            background-color: #ff9900;
            color: #ffffff;
            border: 2px solid #ff9900;
        }

    </style>
</head>
<body>
    <div class="container">
        <h1>KW音乐查询</h1>
        <div class="input-container">
            <input type="text" id="music-id" placeholder="输入音乐ID">
            <button onclick="fetchMusic()">查询音乐</button>
        </div>

        <div class="music-container" id="music-container">
            <div class="music-info" id="music-info">
                <img id="cover" src="" alt="音乐封面">
                <div class="music-details">
                    <p><strong>音乐名称：</strong><span id="name"></span></p>
                    <p><strong>演唱歌手：</strong><span id="singer"></span></p>
                    <p><strong>音乐专辑：</strong><span id="album"></span></p>
                    <p><strong>音乐品质：</strong><span id="quality"></span></p>
                    <p><strong>音乐时长：</strong><span id="interval"></span></p>
                    <p><strong>音乐大小：</strong><span id="size"></span></p>
                    <p><strong>下载链接：</strong><a id="url" href="" download target="_blank">点击下载</a></p>
                </div>
            </div>

            <div class="player">
                <button class="play-btn" onclick="togglePlay()">
                    <img id="play-icon" src="https://img.icons8.com/ios-glyphs/30/ffffff/play--v1.png" alt="播放按钮">
                </button>
                <div class="progress-container">
                    <span id="current-time">00:00</span>
                    <div class="progress-bar-container" onclick="seek(event)">
                        <div class="progress-bar" id="progress-bar"></div>
                    </div>
                    <span id="duration-time">00:00</span>
                </div>
            </div>
        </div>

        <audio id="audio" src=""></audio>
    </div>

    <div class="footer-content">
        <p>本页面仅供学习交流使用，请勿用于商业用途。</p>
        <p>作者: TobDeng0 <a href="https://github.com/TobDeng0/KW-Music-crack-KW-" target="_blank">GitHub源码</a></p>
    </div>

    <script>
        swal("重要提醒", "此网站的任何内容都来自网络如有侵权请联系站长", "warning");

        let isPlaying = false;

        function fetchMusic() {
            const musicId = document.getElementById('music-id').value;
            if (!musicId) {
                alert('请输入音乐ID');
                return;
            }

            const apiUrl = `https://api.leafone.cn/api/kuwo?id=${musicId}`;

            fetch(apiUrl)
                .then(response => response.json())
                .then(result => {
                    const data = result.data;
                    if (data && data.url) {
                        document.getElementById('music-container').style.display = 'block';
                        document.getElementById('cover').src = data.cover;
                        document.getElementById('name').innerText = data.name;
                        document.getElementById('singer').innerText = data.singer;
                        document.getElementById('album').innerText = data.album;
                        document.getElementById('quality').innerText = data.quality;
                        document.getElementById('interval').innerText = data.interval;
                        document.getElementById('size').innerText = data.size;
                        document.getElementById('url').href = data.url;

                        const audioPlayer = document.getElementById('audio');
                        audioPlayer.src = data.url;

                        updateDuration();
                        resetProgressBar();
                    } else {
                        alert('未找到音乐信息');
                    }
                })
                .catch(error => {
                    console.error('Error fetching music:', error);
                    alert('获取音乐信息失败');
                });
        }

        function togglePlay() {
            const audioPlayer = document.getElementById('audio');
            const playIcon = document.getElementById('play-icon');
            if (isPlaying) {
                audioPlayer.pause();
                playIcon.src = "https://img.icons8.com/ios-glyphs/30/ffffff/play--v1.png";
            } else {
                audioPlayer.play();
                playIcon.src = "https://img.icons8.com/ios-glyphs/30/ffffff/pause--v1.png";
                updateProgressBar();
            }
            isPlaying = !isPlaying;
        }

        function resetProgressBar() {
            const progressBar = document.getElementById('progress-bar');
            progressBar.style.width = '0%';
            document.getElementById('current-time').innerText = '00:00';
            document.getElementById('duration-time').innerText = '00:00';
        }

        function updateDuration() {
            const audioPlayer = document.getElementById('audio');
            audioPlayer.onloadedmetadata = function() {
                document.getElementById('duration-time').innerText = formatTime(audioPlayer.duration);
            };
        }

        function updateProgressBar() {
            const audioPlayer = document.getElementById('audio');
            const progressBar = document.getElementById('progress-bar');

            audioPlayer.addEventListener('timeupdate', () => {
                const percentage = (audioPlayer.currentTime / audioPlayer.duration) * 100;
                progressBar.style.width = `${percentage}%`;
                document.getElementById('current-time').innerText = formatTime(audioPlayer.currentTime);
            });
        }

        function formatTime(seconds) {
            const minutes = Math.floor(seconds / 60);
            const secs = Math.floor(seconds % 60);
            return `${minutes < 10 ? '0' + minutes : minutes}:${secs < 10 ? '0' + secs : secs}`;
        }

        function seek(event) {
            const progressBarContainer = document.querySelector('.progress-bar-container');
            const clickX = event.clientX - progressBarContainer.getBoundingClientRect().left;
            const percentage = clickX / progressBarContainer.offsetWidth;
            const audioPlayer = document.getElementById('audio');
            audioPlayer.currentTime = audioPlayer.duration * percentage;
        }





        //动态背景效果
        !function () {
        //封装方法，压缩之后减少文件大小
        function get_attribute(node, attr, default_value) {
            return node.getAttribute(attr) || default_value;
        }
 
        //封装方法，压缩之后减少文件大小
        function get_by_tagname(name) {
            return document.getElementsByTagName(name);
        }
 
        //获取配置参数
        function get_config_option() {
            var scripts = get_by_tagname("script"),
                script_len = scripts.length,
                script = scripts[script_len - 1]; //当前加载的script
            return {
                l: script_len, //长度，用于生成id用
                z: get_attribute(script, "zIndex", -1), //z-index
                o: get_attribute(script, "opacity", 0.8), //opacity
                c: get_attribute(script, "color", "255,255,255"), //color
                n: get_attribute(script, "count", 350) //count
            };
        }
 
        //设置canvas的高宽
        function set_canvas_size() {
            canvas_width = the_canvas.width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
                canvas_height = the_canvas.height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
        }
 
        //绘制过程
        function draw_canvas() {
            context.clearRect(0, 0, canvas_width, canvas_height);
            //随机的线条和当前位置联合数组
            var e, i, d, x_dist, y_dist, dist; //临时节点
            //遍历处理每一个点
            random_points.forEach(function (r, idx) {
                r.x += r.xa,
                    r.y += r.ya, //移动
                    r.xa *= r.x > canvas_width || r.x < 0 ? -1 : 1,
                    r.ya *= r.y > canvas_height || r.y < 0 ? -1 : 1, //碰到边界，反向反弹
                    context.fillRect(r.x - 0.5, r.y - 0.5, 1, 1); //绘制一个宽高为1的点
                //从下一个点开始
                for (i = idx + 1; i < all_array.length; i++) {
                    e = all_array[i];
                    // 当前点存在
                    if (null !== e.x && null !== e.y) {
                        x_dist = r.x - e.x; //x轴距离 l
                        y_dist = r.y - e.y; //y轴距离 n
                        dist = x_dist * x_dist + y_dist * y_dist; //总距离, m
 
                        dist < e.max && (e === current_point && dist >= e.max / 2 && (r.x -= 0.03 * x_dist, r.y -= 0.03 * y_dist), //靠近的时候加速
                            d = (e.max - dist) / e.max,
                            context.beginPath(),
                            context.lineWidth = d / 2,
                            context.strokeStyle = "#000000",
                            context.moveTo(r.x, r.y),
                            context.lineTo(e.x, e.y),
                            context.stroke());
                    }
                }
            }), frame_func(draw_canvas);
        }
 
        //创建画布，并添加到body中
        var the_canvas = document.createElement("canvas"), //画布
            config = get_config_option(), //配置
            canvas_id = "c_n" + config.l, //canvas id
            context = the_canvas.getContext("2d"), canvas_width, canvas_height,
            frame_func = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (func) {
                window.setTimeout(func, 1000 / 40);
            }, random = Math.random,
            current_point = {
                x: null, //当前鼠标x
                y: null, //当前鼠标y
                max: 20000 // 圈半径的平方
            },
            all_array;
        the_canvas.id = canvas_id;
        the_canvas.style.cssText = "position:fixed;top:0;left:0;z-index:" + config.z + ";opacity:" + config.o;
        get_by_tagname("body")[0].appendChild(the_canvas);
 
        //初始化画布大小
        set_canvas_size();
        window.onresize = set_canvas_size;
        //当时鼠标位置存储，离开的时候，释放当前位置信息
        window.onmousemove = function (e) {
            e = e || window.event;
            current_point.x = e.clientX;
            current_point.y = e.clientY;
        }, window.onmouseout = function () {
            current_point.x = null;
            current_point.y = null;
        };
        //随机生成config.n条线位置信息
        for (var random_points = [], i = 0; config.n > i; i++) {
            var x = random() * canvas_width, //随机位置
                y = random() * canvas_height,
                xa = 2 * random() - 1, //随机运动方向
                ya = 2 * random() - 1;
            // 随机点
            random_points.push({
                x: x,
                y: y,
                xa: xa,
                ya: ya,
                max: 6000 //沾附距离
            });
        }
        all_array = random_points.concat([current_point]);
        //0.1秒后绘制
        setTimeout(function () {
            draw_canvas();
        }, 100);
    }();
    </script>
</body>
</html>
